<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Lihat_nilai extends zulController{
	
	function __construct(){
		parent::__construct();
		$this->load->model("nilai_mahasiswa_model");
		$this->load->model("master_matkul_model");
		$this->load->model("master_kelas_model");
		$this->load->model("master_jurusan_model");
		$this->load->model("master_program_model");
		$this->load->model("master_tahun_ajaran_model");
		$this->checkLogin();
	}
	function index(){
		/*-----------------------------*/
		$colModel['NO'] = array('No', 20, TRUE, 'center', 0);
        $colModel['NAMA'] = array('Nama Mahasiswa', 200, FALSE, 'center', 1);
		$colModel['NAMA_MATA_KULIAH'] = array('Nama Mata Kuliah', 200, FALSE, 'center', 1);
		$colModel['NILAI'] = array('Nilai', 110, FALSE, 'center', 1);
		// $colModel['EDIT'] = array('Edit', 70, FALSE, 'center', 0);
        $gridParams = array(
            'width' => 'auto',
            'height' => '390',
            'rp' => 15,
            'rpOptions' => '[10,15,20,25,40]',
            'pagestat' => 'Displaying: {from} to {to} of {total} items.',
            'blockOpacity' => 0.5,
            'title' => 'Daftar Nilai Mahasiswa'
        );
        // $buttons[] = array('Tambah', 'add', 'nilai_mahasiswa');
        // $buttons[] = array('separator');
		// $buttons[] = array('Kembali', 'prev', 'nilai_mahasiswa');
		
        $grid_js = build_grid_js('flex1', site_url("lihat_nilai/grid_lihat_nilai/"), $colModel, 'nilai_mahasiswa.ID_MATA_KULIAH', 'ASC', $gridParams, false);

        $data['title'] = "Daftar Nilai Mahasiswa";
        $data['info'] = "Daftar Nilai Mahasiswa";
        $data['js_grid'] = $grid_js;


        $data['added_js'] =
                "<script type='text/javascript'>
			function nilai_mahasiswa(com,grid)
			{
				if (com=='Pilih Semua')
				{
					$('.bDiv tbody tr',grid).addClass('trSelected');
				}
				
				if (com=='Hapus Pilihan')
				{
					$('.bDiv tbody tr',grid).removeClass('trSelected');
				}
				if (com=='Kembali')
				{
					location.href='" . base_url() . "index.php/master_mahasiswa'; 
				}
				if (com=='Tambah')
				{
					location.href='" . base_url() . "index.php/nilai_mahasiswa/form_nilai/'; 
				}
				
				if (com=='Hapus')
				{
				   if($('.trSelected',grid).length>0){
					   if(confirm('Anda yakin ingin mengaktifkan ' + $('.trSelected',grid).length + ' buah data?')){
							var items = $('.trSelected',grid);
							var itemlist ='';
							for(i=0;i<items.length;i++){
								itemlist+= items[i].id.substr(3)+',';
							}
							$.ajax({
							   type: 'POST',
							   url: '" .base_url('index.php/nilai_mahasiswa/delete_nilai')."',
							   data: 'items='+itemlist,
							   success: function(data){
								$('#flex1').flexReload();
								alert(data);
							   }
							});
						}
					} else {
						return false;
					} 
				}
			} 
			</script>
			";
		/*-----------------------------*/
	
		$data["active"] = "transaksi";
		$data["qmatkul"]= $this->master_matkul_model->get();
		$data["qkelas"]= $this->master_kelas_model->get();
		$data["qt_ajaran"]= $this->master_tahun_ajaran_model->get();
		$data["qjurusan"]= $this->master_jurusan_model->get();
		$data["qprogram"]= $this->master_program_model->get();
		$data["content"]= $this->load->view("form_lihat_nilai",$data,true);
		$this->load->view("main_new",$data);
	}
	public function cari()
	{
		$colModel['NO'] = array('No', 20, TRUE, 'center', 0);
        $colModel['NAMA'] = array('Nama Mahasiswa', 200, FALSE, 'center', 1);
		$colModel['NAMA_MATA_KULIAH'] = array('Nama Mata Kuliah', 200, FALSE, 'center', 1);
		$colModel['NILAI'] = array('Nilai', 110, FALSE, 'center', 1);
		// $colModel['EDIT'] = array('Edit', 70, FALSE, 'center', 0);
        $gridParams = array(
            'width' => 'auto',
            'height' => '390',
            'rp' => 15,
            'rpOptions' => '[10,15,20,25,40]',
            'pagestat' => 'Displaying: {from} to {to} of {total} items.',
            'blockOpacity' => 0.5,
            'title' => 'Daftar Nilai Mahasiswa'
        );
		$tahun	= $this->input->post("tahun");		
		$semester	= $this->input->post("semester");		
		$kelas	= $this->input->post("kelas");		
		$jurusan	= $this->input->post("jurusan");		
		$program	= $this->input->post("program");		
        $grid_js = build_grid_js('flex1', site_url("lihat_nilai/grid_lihat_nilai/" . $tahun . "/" . $semester . "/" . $kelas . "/" . $jurusan . "/" . $program), $colModel, 'nilai_mahasiswa.ID_MATA_KULIAH', 'ASC', $gridParams, FALSE);

        $data['title'] = "Daftar Nilai Mahasiswa";
        $data['info'] = "Daftar Nilai Mahasiswa";
        $data['js_grid'] = $grid_js;


        $data['added_js'] =
                "<script type='text/javascript'>
			function nilai_mahasiswa(com,grid)
			{} 
			</script>
			";
		$data["active"] = "master";
		$this->load->view("grid",$data);
		// $this->load->view("main_new",$data);
	}
	function grid_lihat_nilai($tahun=FALSE,$semester=FALSE,$kelas=FALSE,$jurusan=FALSE,$program=FALSE){
		$valid_fields = array('ID_MATA_KULIAH', 'ID_MAHASISWA', 'NAMA', 'NILAI','NAMA_MATA_KULIAH');
        $this->flexigrid->validate_post('nilai_mahasiswa.ID_MATA_KULIAH', 'ASC', $valid_fields);
		$join	= array(
			array("table"=>"nilai_mahasiswa","join_key"=>"ID_MATA_KULIAH","join_table"=>"master_matkul","join_type"=>"left"),
			array("table"=>"nilai_mahasiswa","join_key"=>"ID_MAHASISWA","join_table"=>"master_mahasiswa","join_type"=>"left"),
		);
		$column	= array('nilai_mahasiswa.ID_MATA_KULIAH', 'nilai_mahasiswa.ID_MAHASISWA', 'NAMA', 'NILAI', 'NAMA_MATA_KULIAH');
		if($tahun == TRUE || $semester == TRUE || $kelas == TRUE || $jurusan == TRUE || $program == TRUE){
			$records = $this->nilai_mahasiswa_model->get_joinFG($join,array("nilai_mahasiswa.ID_TAHUN_AJARAN"=>$tahun,"nilai_mahasiswa.SEMESTER"=>$semester),$column,TRUE);
		} else {
			$records = $this->nilai_mahasiswa_model->get_joinFG($join,FALSE,$column);
		}
       
        $this->output->set_header($this->config->item('json_header'));
        $no = 1;
        foreach ($records['records']->result() as $row) {
            $record_items[] = array($row->ID_MATA_KULIAH,
                $no,
				$row->NAMA,
				$row->NAMA_MATA_KULIAH,
				$row->NILAI,
            );
            $no++;
        }
        if (isset($record_items))
            $this->output->set_output($this->flexigrid->json_build($records['record_count'], $record_items));
        else
            $this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}
	function select_kelas(){
		$id		= $this->input->post("jurusan");
        $getKelas= $this->master_kelas_model->get_by(array("ID_JURUSAN"=>$id,"STATUS"=>1));
		foreach($getKelas as $row){
			if(count($getKelas) > 0){
				echo "<option value=".$row["ID_KELAS"].">".$row["NAMA_KELAS"]."</option>";
			}
		}
	}
}
?>